<?php

	# PAGE SETTING
	 $class_nam   ='';
	 $add_function   ='';
	class userClass
	{
		function listAllUsers($assigned_user,$order_id=0,$type=''){
			global $wpdb;
			
			if($order_id!=0){
				$sql = "SELECT wp_users.ID,
							   wp_users.user_login
							    FROM   wp_users
					    INNER JOIN wp_spec_assigned_orders ON wp_users.id= wp_spec_assigned_orders.assigned_to	   
						WHERE 1=1 AND wp_spec_assigned_orders.order_id=".$order_id." GROUP BY ID";
						
			}
			else
				$sql = "select ID,user_login from wp_users";
			$result = mysql_query($sql) or die ('Error, query failed');
			if (mysql_num_rows($result) > 0 )
			{
				while ($row = mysql_fetch_assoc($result))
				{
					$user_id       		 = $row['ID'];
					$user_login      = $row['user_login'];
					$user = get_userdata($user_id);
					$select = ($assigned_user == $user_id ? 'selected="selected"' : '');
					if(isset($user->caps["designer"])){
							if($user->caps["designer"]==1){
				
							if($type!='photographer')
							$option.="<option value='".$user_id."' ".$select.">".$user_login."(Designer)</option>";
							}
						}
					else 
					if(isset($user->caps["photographer"])){
							if($user->caps["photographer"]==1){
							
							if($type!='designer')
							$option.="<option value='".$user_id."' ".$select.">".$user_login."(Photographer)</option>";
							}
						}
					else {
					if($user_id!=1)
						$option_customer.="<option value='".$user_id."' ".$select.">".$user_login."</option>";
					}
					
					
				}
			}
		if($type=='customer')	
			return $option_customer;
		else	
			return $option;	
		}
		function getUserName($id){
			$result = mysql_query("SELECT user_login FROM wp_users WHERE ID=".$id."");
			if (mysql_num_rows($result) > 0 )
			{
				while ($row = mysql_fetch_assoc($result))
				{
				return	$user_login       		 = $row['user_login'];			
				}
			}
		}
		function getAssigned($order_id,$usertype){
				$sql = "SELECT wp_users.ID,
							   wp_users.user_login
							    FROM   wp_users
					    INNER JOIN wp_spec_assigned_orders ON wp_users.id= wp_spec_assigned_orders.assigned_to	   
						WHERE 1=1 AND wp_spec_assigned_orders.order_id=".$order_id." GROUP BY ID";
					
			$result = mysql_query($sql) or die ('Error, query failed');
			if (mysql_num_rows($result) > 0 )
			{
				while ($row = mysql_fetch_assoc($result))
				{
					$user_id       		 = $row['ID'];
					$user_login          = $row['user_login'];
					$user = get_userdata($user_id);
					
					if(isset($user->caps["designer"])){
							if($user->caps["designer"]==1){
								
								if($usertype == 'designer')
								$assigned = $user_id ;
							
							}
						}
					else 
					if(isset($user->caps["photographer"])){
							if($user->caps["photographer"]==1){
							
								if($usertype == 'photographer')
								$assigned = $user_id ;
							}
						}
					
					
					
				}
			}		
		return $assigned;
		}
		function getUserDetails($id){
			$query = mysql_query("SELECT * FROM wp_spec_user_details WHERE users_id=".$id."");
			}
		function updateUserInfo($id,$meta_key,$meta_value){
			
		//	echo "SELECT meta_value FROM wp_usermeta WHERE user_id=".$id." AND meta_key ='".$meta_key."'";
			$result = mysql_query("SELECT meta_value FROM wp_usermeta WHERE user_id=".$id." AND meta_key ='".$meta_key."'");
	
			if (mysql_num_rows($result) > 0 )
			{
				mysql_query("UPDATE  `wp_usermeta` SET  `meta_value` =  '".$meta_value."' WHERE  user_id=".$id." AND meta_key ='".$meta_key."'");
			}else{
				mysql_query("INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) 
														VALUES (NULL, '".$id."', '".$meta_key."', '".$meta_value."');");
			}
			
			}	
	}
	



?>